#include "xcocos_utils.h"
#include "xtransition_game_info.h"
#include <xscene_manager.h>
namespace zdh
{
	//--------------------------------------------------------------------------------------
	CCTransitionScene * utils::createTransition(int paramTransitionID, float paramDur, CCScene* paramDestScene)
	{
		switch (paramTransitionID)
		{
		case ETID_FADE_WHITE_TRANSITION:
			return CCTransitionFade::create(paramDur, paramDestScene, ccWHITE);//  XFadeWhiteTransition::create(paramDur, paramDestScene);

		case ETID_FLIP_X_LEFT_OVER:
			return CCTransitionFlipX::create(paramDur, paramDestScene, kCCTransitionOrientationLeftOver);

		case ETID_FLIP_X_RIGHT_OVER:
			return CCTransitionFlipX::create(paramDur, paramDestScene, kCCTransitionOrientationRightOver);

		case ETID_FLIP_Y_UP_OVER:
			return CCTransitionFlipY::create(paramDur, paramDestScene, kCCTransitionOrientationUpOver);

		case ETID_FLIP_Y_DOWN_OVER:
			return CCTransitionFlipY::create(paramDur, paramDestScene, kCCTransitionOrientationDownOver);

		case ETID_FLIP_ANGULAR_LEFT_OVER:
			return CCTransitionFlipAngular::create(paramDur, paramDestScene, kCCTransitionOrientationLeftOver);

		case ETID_FLIP_ANGULAR_RIGHT_OVER:
			return CCTransitionFlipAngular::create(paramDur, paramDestScene, kCCTransitionOrientationRightOver);

		case ETID_CUSTOM_GAME_INFO:
			return XTransitionGameInfo::create(paramDur, paramDestScene);
		default:
			return nullptr;
		}
	}
	namespace utils
	{
		//--------------------------------------------------------------------------------------
		CCSprite * createSprite(const char * paramFileName, float paramX /*= 0.0f*/, float paramY /*= 0.0f*/)
		{
			CCSprite * pRet = CCSprite::create(paramFileName);
			pRet->setPosition(paramX, paramY);
			pRet->setAnchorPoint(0, 0);
			return pRet;
		}
		//--------------------------------------------------------------------------------------
		CCSprite * createSpriteByFrameCache(const char * paramFrameName, float paramX /*= 0.0f*/, float paramY /*= 0.0f*/)
		{
			CCSprite * pRet = CCSprite::createWithSpriteFrameName(paramFrameName);
			pRet->setPosition(paramX, paramY);
			pRet->setAnchorPoint(0, 0);
			return pRet;
		}
		//--------------------------------------------------------------------------------------
		void TransitionScene(int paramTransitionID, float paramDur, int paramSceneID)
		{
			CCScene * pScene = SCENE_MGR->GetScene(paramSceneID);
			CCTransitionScene * pTran = createTransition(paramTransitionID, paramDur, pScene);
			CCDirector::sharedDirector()->replaceScene(pTran);
		}
		//--------------------------------------------------------------------------------------
		CCAnimate * createAnimate(const char * paramFileNameFormat, XInt paramStartCode, XInt paramEndCode, float paramDur)
		{
			CCArray stList;
			XAnsiString strTemp;
			for (XInt i = paramStartCode; i <= paramEndCode; i++)
			{
				strTemp.printf(paramFileNameFormat, i);
				CCSpriteFrame * p = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(strTemp.c_str());
				stList.addObject(p);
			}
			CCAnimation * pAni = CCAnimation::createWithSpriteFrames(&stList, paramDur / (paramEndCode - paramStartCode + 1));
			//pAni->setLoops(1);
			CCAnimate * pRet = CCAnimate::create(pAni);
			return pRet;
		}
		//--------------------------------------------------------------------------------------
		void ExitGame()
		{
			STREAM_INFO << "OnExit";
			#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
					CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.", "Alert");
			#else
					CCDirector::sharedDirector()->end();
			#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
					exit(0);
			#endif
			#endif
		}

	}
}
